package cn.neusoft.controller;

import cn.neusoft.pojo.LogUser;
import cn.neusoft.vo.ResultBean;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/log")
public class LoginController {

    @PostMapping("/in")     // post + /log/in
    public ResultBean login(HttpSession session,@RequestBody LogUser loguser){

        System.out.println("--------LoginController------login------------");
        System.out.println(loguser);

        if ("admin".equals(loguser.getUsername()) && "123456".equals(loguser.getPassword())){
            //登录成功  将登录成功的用户信息存入session
            System.out.println("登录成功："+session.getId());
            session.setAttribute("adminUser",loguser);
            return ResultBean.SUCCESS("admin");
        }

        return ResultBean.ERROR("登录失败,用户名或密码错误");
    }

    @GetMapping("/out")     // get + /log/out
    public ResultBean logout(HttpSession session){
        session.removeAttribute("adminUser");
        return ResultBean.SUCCESS();
    }

}
